﻿using FellowshipOne.API.Base;
using FellowshipOne.API.People.Model;
using FellowshipOne.API.People.Sets;
using FellowshipOne.API.Realms;
using MasVida.WebApi.Controllers;
using MasVida.WebApi.Models.Requests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace MasVida.WebApi.Tests.Controllers
{
    [TestClass]
    public class PushNotificationsControllerTests
    {
        [TestMethod]
        public void Verify_psuh_notification_user_is_registered()
        {
            
            Mock<IPeople> personMock = new Mock<IPeople>();
            const int personId = 654;
            personMock.Setup(
                ac => ac.Update(It.IsAny<Person>(), personId.ToString()));
            personMock.Setup(p => p.Get(It.IsAny<string>())).Returns(new Person() { ID = personId, FirstName = "Ruben", LastName = "Cardenas" });
            IRestClient client = GetRestClient(personMock);
            PushNotificationsController controller = new PushNotificationsController(client);

            controller.RegisterToken(new WebHookPushRequest());
            personMock.Verify(ac => ac.Update(It.IsAny<Person>(), personId.ToString()));
        }

        private IRestClient GetRestClient(Mock<IPeople> person = null)
        {
            IRestClient restClient = Mock.Of<IRestClient>();
            if (person != null)
            {
                Mock<IPersonRealm> personsMock = new Mock<IPersonRealm>();
                personsMock.Setup(p => p.People).Returns(person.Object);
                restClient.PeopleRealm = personsMock.Object;
            }
            return restClient;
        }
    }
}
